<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>临床诊疗项目管理</title>
    <link rel="stylesheet" type="text/css" href="/static/easyui/css/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../static/easyui/css/icon.css">
    <script type="text/javascript" src="../../static/jquery/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../../static/easyui/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../static/js/spell.js"></script>

</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north'" style="height:60%;">
        <table id="clinic_item"></table>
        <div id="tb" style="padding:5px;">
            <div>
                类别
                <input id="item_class" name="dept">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="adminFlag" value="0">代码</input>
                <input type="radio" name="adminFlag" value="1" checked="checked">拼音码</input>
                <label style="margin-left: 20px" for="code_gps" id="code_text">拼音码定位</label>
                <input id="code_gps">
                <label style="margin-left: 20px" for="code_filter" id="filter_text">拼音码筛选</label>
                <input id="code_filter" >
            </div>
        </div>
    </div>

    <div data-options="region:'south'" style="height:50px;min-height: 50px">
        <div style="padding: 5px;">
            <a href="#" id="add_project" class="easyui-linkbutton" iconCls="icon-add" onclick="">新增项目</a>
            <a href="#" id="del_project" class="easyui-linkbutton" iconCls="icon-remove">删除项目</a>
            <a href="#" id="add_alias" class="easyui-linkbutton" iconCls="icon-add" >添加别名</a>
            <a href="#" id="del_alias" class="easyui-linkbutton" iconCls="icon-remove">删除别名</a>
            <a href="#" id="add_vs" class="easyui-linkbutton" iconCls="icon-add" >添加对照</a>
            <a href="#" id="del_vs" class="easyui-linkbutton" iconCls="icon-remove">删除对照</a>
            <a href="#" id="reload_html" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
            <a href="#" id="save_data" class="easyui-linkbutton" iconCls="icon-save">保存</a>
            <a href="#" id="close_html" class="easyui-linkbutton" iconCls="icon-remove">关闭</a>
        </div>
    </div>
    <div data-options="region:'west'" title="临床诊疗项目正/别名称列表" style="width:30%">
        <table id="clinic_item_name"></table>
    </div>
    <div data-options="region:'center',title:'临床诊疗项目对照项目列表'">
        <table id="clinic_vs_charge"></table>
    </div>
</div>
<div id="add_pro_win">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'north',split:false,height:80,border:0">
            <form id="pro_form" method="post">
                <table cellpadding="5">
                    <tr>
                        <td style="width: 75px"></td>
                        <td style="width: 200px">
                            <input type="radio" name="org_type" value="0" checked="checked">全院公用</input>
                            <input type="radio" name="org_type" value="1">科室专用</input>
                        </td>
                        <td style="width: 75px">门诊科室:</td>
                        <td style="width: 200px"><input id="clinic_org" class="easyui-combobox" data-options="valueField: 'id', textField: 'deptName'"></td>
                    </tr>
                    <tr>
                        <td>项目代码:</td>
                        <td><input id="item_code" class="easyui-textbox"  data-options="required:true,missingMessage:'项目代码必填',validType : 'isExisted[{itemCode:true}]'" style="width: 160px"></td>
                    <td>项目名称:</td>
                    <td><input id="item_name" class="easyui-textbox" data-options="required:true,missingMessage:'项目名称必填',validType : 'isExisted[{itemName:true}]'" style="width: 160px"></td>
                </tr>
                </table>
            </form>
        </div>
        <div data-options="region:'center'" style="padding:10px;border:0">
            <table id="dept_grid" >
            </table>
        </div>
        <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 15px;">
            <a href="javascript:void(0)" data-options="iconCls:'icon-ok'" class="easyui-linkbutton" id="yes_pro_form">确定</a>
            <a href="javascript:void(0)" data-options="iconCls:'icon-cancel'" class="easyui-linkbutton" id="cancle_pro_form">取消</a>
        </div>
    </div>
</div>
<script>
    var base_url = '/service/clinicItem/'
    $.extend($.fn.datagrid.methods, {
        editCell: function(jq,param){
            return jq.each(function(){
                var opts = $(this).datagrid('options');
                var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
                for(var i=0; i<fields.length; i++){
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor1 = col.editor;
                    if (fields[i] != param.field){
                        col.editor = null;
                    }
                }
                $(this).datagrid('beginEdit', param.index);
                for(var i=0; i<fields.length; i++){
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor = col.editor1;
                }
            });
        }
    });

    $.extend({
        ajaxAsync : function(url,data,callback,type,async){
            return $.ajax({
                type: type,
                url: url,
                async : async,   // true 异步,false 同步
                data: data,
                success: callback,
                'contentType': 'application/json'
            });
        }
    })
    $.extend($.fn.validatebox.defaults.rules, {
        isExisted: {
            validator: function(value,param){
                var rows = $('#clinic_item').datagrid('getRows')
                var code = ''
                if(param[0].itemCode)
                    code = 'itemCode'
                if(param[0].itemName)
                    code = 'itemName'
                for(var index = rows.length - 1;index > -1;index--) {
                    if(rows[index][code] == value){
                        return false
                    }
                }
                return true
            },
            message: '内容已存在'
        },
        nameIsExisted :{
          validator : function(value){
              var rows = $('#clinic_item_name').datagrid('getRows')
              var select_index = $('#clinic_item_name').datagrid('getRowIndex',$('#clinic_item_name').datagrid('getSelected'))
              for(var index = rows.length - 1;index > -1;index--) {
                  if(index != select_index && rows[index].itemName == value){
                      return false
                  }
              }
              return true
          },
            message : '名称已存在'
        }
    });

</script>
<script src="js/clinic-item.js"></script>
</body>
</html>